package com.wfm.leetcode.editor.cn;

import java.util.ArrayDeque;
import java.util.Deque;

public class P剑指Offer09用两个栈实现队列{
//leetcode submit region begin(Prohibit modification and deletion)
class CQueue {

    Deque<Integer> in = null;
    Deque<Integer> out = null;
    public CQueue() {
        in = new ArrayDeque<>();
        out = new ArrayDeque<>();
    }
    
    public void appendTail(int value) {
        in.push(value);
    }
    
    public int deleteHead() {
        if(out.isEmpty()){
            if(in.isEmpty()) return -1;
            else {
                while (!in.isEmpty()) {
                    out.push(in.pop());
                }
            }
        }
        return out.pop();
    }
}

/**
 * Your CQueue object will be instantiated and called as such:
 * CQueue obj = new CQueue();
 * obj.appendTail(value);
 * int param_2 = obj.deleteHead();
 */
//leetcode submit region end(Prohibit modification and deletion)
}